package acm.pta13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class 包装机 {
    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int max = sc.nextInt();
        Queue<Character>[] queue=new Queue[n+1];
        Stack<Character> stack=new Stack<>();
        StringBuilder res=new StringBuilder();
        for (int i = 1; i < queue.length; i++) {
            char[] chars = sc.nextLine().toCharArray();
            queue[i]=new LinkedList<>();
            for (char c : chars) {
                queue[i].add(c);
            }
        }
        String[] line = sc.nextLine().split(" ");
        int length = line.length-1;
        for (int i = 0; i < length; i++) {
            int a = Integer.parseInt(line[i]);
            if (a==0){
                if(!stack.isEmpty()){
                    res.append(stack.pop());
                }
            }else {
                if (queue[a].isEmpty()){
                    continue;
                }
                if(stack.size()==max) {
                    res.append(stack.pop());
                }
                stack.push(queue[a].poll());
            }
        }
        System.out.println(res.toString().trim());
    }
    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
